﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin1_Travel : System.Web.UI.Page
{
    eStoreDataContext db = new eStoreDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        rpt_Category.DataSource = db.ad_tourTravel();
        rpt_Category.DataBind();
    }
   
    protected void btnxoa_Click(object sender, EventArgs e)
    {

    }
    protected void lbtChinhSua_Click(object sender, EventArgs e)
    {
        panel_Edit.Visible = true;
        int travelid = int.Parse(((LinkButton)sender).CommandArgument.ToString());

        var travel = db.Travels.Single(c => c.TravelId == travelid);
        txt_DateStart_Edit.Text = travel.DateStart;
        txt_DateStart_EditVN.Text = travel.DateStartVN;
        txt_TravelId.Text = travel.TravelId.ToString();
        ddl_Guide_Edit.DataSource = db.Guides; ;
        ddl_Guide_Edit.DataValueField = "GuideId";
        ddl_Guide_Edit.DataTextField = "Name";
        ddl_Guide_Edit.DataBind();
    }
    //protected void lbt_Add_New_Click(object sender, EventArgs e)
    //{
    //    panel_Add.Visible = true;

    //    ddl_Category.DataSource = db.Categories.Where(c => c.Activated == true);
    //    ddl_Category.DataValueField = "CategoryId";
    //    ddl_Category.DataTextField = "NameVN";
    //    ddl_Category.DataBind();

    //    ddl_Location.DataSource = db.getLocationByCat(int.Parse(ddl_Category.SelectedValue));
    //    ddl_Location.DataValueField = "LocationId";
    //    ddl_Location.DataTextField = "NameVN";
    //    ddl_Location.DataBind();

    //    ddl_Tour.DataSource = db.getTourLocation(int.Parse(ddl_Category.SelectedValue));
    //    ddl_Tour.DataValueField = "TourId";
    //    ddl_Tour.DataTextField = "TourName";
    //    ddl_Tour.DataBind();

    //    ddl_Guide.DataSource = db.Guides; ;
    //    ddl_Guide.DataValueField = "GuideId";
    //    ddl_Guide.DataTextField = "Name";
    //    ddl_Guide.DataBind();
    //}
    //protected void btnInsert_Click(object sender, EventArgs e)
    //{
    //    try
    //    {
    //        var travel = new Travel
    //        {
    //            TourId = int.Parse(ddl_Tour.SelectedValue),
    //            DateStart = txt_DateStart.Text,
    //            GuideId = int.Parse(ddl_Guide.SelectedValue),
    //            Activated = bool.Parse(rad_Available.SelectedValue),

    //        };
           
    //        //2.them vao
    //        db.Travels.InsertOnSubmit(travel);
    //        //3. luu
    //        db.SubmitChanges();
    //        Response.Redirect("Travel.aspx");
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write(ex.Message);
    //    }
    //}

    protected void lbt_CloseEdit_Click(object sender, EventArgs e)
    {
        
        panel_Edit.Visible = false;
    }

    protected void btn_Save_Edit_Click(object sender, EventArgs e)
    {
        var travel = db.Travels.Single(c => c.TravelId == int.Parse(txt_TravelId.Text));
        travel.DateStart = txt_DateStart_Edit.Text;
        travel.DateStartVN = txt_DateStart_EditVN.Text;
        travel.GuideId = int.Parse(ddl_Guide_Edit.SelectedValue);
        db.SubmitChanges();
    }
}